<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2017/9/11
 * Time: 10:55
 */
use yii\widgets\ListView;
use frontend\models\Category;

?>
<link rel="stylesheet"  href="./mycss/weixinlunbo.css">   
 
<div class="homescreenadd"   onclick="dolink('');"  ><i class="homescreendw"></i><span  id="showareainfo">定位地址信息...</span><i class="fa fa-angle-right"></i></div>
<div class="homscrsear"  onclick="dolink('');"   >
<input style="    background-position: 3% center;" readonly type="text" placeholder="请输入店铺名、商品名">
</div>

<div id="wrapper" style="top:73px;">

	<div id="scroller">

		<!--展示-->
		<div class="bannerCon" style="margin-top:0px;">
			<section id="slider" class="swipe" style="visibility: visible;">
				<div class="swipe-wrap">
					<div class="wrap" ><a href="#"><img src="http://img1.imgtn.bdimg.com/it/u=3469073068,3426495253&fm=11&gp=0.jpg" style="width:100%; height:114px;" alt=""></a></div>
                    <div class="wrap" ><a href="#"><img src="http://img0.ph.126.net/XjXl3KcowmXdE1pcsFVe8g==/1067353111787095545.jpgg" style="width:100%; height:114px;" alt=""></a></div>
				</div>
				<div class="bgboxgo">
					<div class="botton-box mBxCm" id="abdcd">
						<span class="on"></span>
                        <span class=""></span>
					</div>
				</div>
			</section>
		</div>


		<!--分类部分-->
		<div class="categoryContainer">
			<ul>
				<?php foreach (Category::getNavCat(['status'=> 10, 'is_show' => 1]) as $key => $value){?>
				<li>
					<a><img src="http://img0.ph.126.net/XjXl3KcowmXdE1pcsFVe8g==/1067353111787095545.jpg"  class="category_img"><span><?= $value['name'];?></span></a>
				</li>
                <?php }?>
				<li onclick="dolink('#');"  >
				<a><img style="height: 33px" src="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1505882222&di=39811cb3bfbb7228e78d952ab79ea1ae&imgtype=jpg&er=1&src=http%3A%2F%2Fpic.58pic.com%2F58pic%2F15%2F51%2F35%2F41n58PIC3We_1024.png" class="category_img"><span>更多</span></a>
				</li>
			</ul>
		</div>
		<!--展示-->


		<!-- 专题页 -->
<!--		<div class="advertisement"> -->
<!--			-->
<!--			<ul class="adver" style="border:none;" onclick="dolink('');">-->
<!--				<li style="width:100%;">-->
<!--					<a href="javascript:void(0);"><img  style="width:100%;" src=""></a>-->
<!--                </li>-->
<!--            </ul>-->
<!--        </div>-->

			<div class="homscrbusinCon">
				<div class="homscrbusintit"><h3>热销商品</h3></div>

				<div id="pullDown" style="display:none;">
					<span class="pullDownIcon"></span><span class="pullDownLabel">下拉刷新...</span>
				</div>

				<div class="homscrbusinBox">
					<ul   id="supplierlist">
                        <a href="">
                            <li>
                                <div class="homscrbusinimg">
                                    <img src="">
                                </div>
                                <div class="listbox">
                                    <div class="homscrbusinR">
                                        <div class="homscrbusint">
                                            热销商品
                                        </div>
                                        <div class="homscrbusinsale">
                                            <i class="fa fa-star"></i>
                                            <i class="fa fa-star"></i>
                                            <i class="fa fa-star"></i>
                                            <span>月售155单</span>
                                        </div>
                                        <div class="homscrbusinpric" style="overflow:auto;">
                                            <span>起送价￥20</span>
                                            <b>|</b>
                                            <span>配送费￥5</span>
                                            <b>|</b>
                                            <span>商品规格</span>
                                        </div>
                                        <div class="homscrbusinadd" >
                                            距3公里
                                        </div>
                                    </div>
                                </div>
                            </li>
                        </a>
					</ul>
				</div>
				<center>
					<div id="pullUp" style="border-top:0px; ">
						<div style="width:35%; float:left;text-align:right;"><span class="pullUpIcon" style="  margin-left:60%;"></span></div>
						<div style="width:65%; float:left;text-align:left;"><span class="pullUpLabel">上拉加载更多...</span></div>
					</div>
				</center>


			</div>

			<!--首页结束-->

        <?php use yii\data\ArrayDataProvider;

        $data = [
        ['id' => 1, 'name' => 'name 1'],
        ['id' => 2, 'name' => 'name 2'],
        ['id' => 100, 'name' => 'name 100'],
        ];

        $dataProvider = new ArrayDataProvider([
        'allModels' => $data,
        'pagination' => [
        'pageSize' => 1,
        ],
        'sort' => [
        'attributes' => ['id', 'name'],
        ],
        ]);?>

        <?=ListView::widget([
        'dataProvider' => $dataProvider,
        'itemOptions' => ['class' => 'item'],
        'itemView' => '_item_view',
        'pager' => ['class' => \kop\y2sp\ScrollPager::className()]
        ]);?>
		</div>
	</div>
<script>
    var can_show = true;
    var page = 1;
    var catid = 0;
    var order = 0;
    var qsjid = 0;
    var typeid = 0;
    var myaddress = '';
    var search_input = '';
    var shopshowtype  = '>';
    var checknext = false;
    var lat = '';
    var lng = '';
    var addressname = '';
    var is_loading = false;

//    $(function(){
//
//
//        <{if !empty($lng) && !empty($lat) &&  !empty($addressname)  }>
//        $('#showareainfo').text(addressname);
//        shopdata();
//        <{else}>
//        getLocation();
//        $('#loading').show();
//        <{/if}>
//
//    });
    function getLocation()
    {

        if (navigator.geolocation)
        {
            navigator.geolocation.getCurrentPosition(showPosition,showError);
        }
        else{
            $('#showareainfo').text("浏览器不支持定位");shopdata();
        }
    }

    function showPosition(position)
    {
        $.getScript('http://api.map.baidu.com/geocoder/v2/?ak=$baidumapkey&callback=renderReverse&location='+position.coords.latitude+','+position.coords.longitude+'&output=json&pois=0&coordtype=wgs84ll');
        //$.getScript('http://api.map.baidu.com/geocoder/v2/?ak=<{$baidumapkey}>&callback=renderReverse&location='+position.coords.latitude+','+position.coords.longitude+'&output=json&pois=0&coordtype=wgs84ll');
        // $.getScript('http://api.map.baidu.com/geocoder/v2/?ak=<{$baidumapkey}>&callback=renderReverse&location=23.036989,114.3679&output=json&pois=0&coordtype=wgs84ll');
    }
    function renderReverse(datas){

        if(datas.status == 0){

            $('#showareainfo').text(datas.result.formatted_address);
            $.ajax({
                type: 'GET',
                //url: '<{ofunc type=url link="/wxsite/saveloation/datatype/json"}>',
                url: 'http://www.baidu.com',
                async:false,
              //	data: {'lat':23.036989,'lng':114.3679},
              data: {'lat':datas.result.location.lat,'lng':datas.result.location.lng,'addressname':datas.result.formatted_address},
              dataType: 'json',success: function(content) {//var info = JSON.parse(content);
                 // $(allobj).eq(i).find('.juliid').eq(0).text(content.msg);
                 if(content.error == false){
                    shopdata();
                 }else{
                      shopdata();// alert(content.msg);
                    }
                 },
                 error: function(content) {
                    shopdata();//alert('提交数据失败');
                 }
              });

        }else{
            shopdata();
            $('#showareainfo').text('定位失败');
        }
    }
    function showError(error)
    {
        $('#showareainfo').text("定位失败");
        switch(error.code)
        {

            case error.PERMISSION_DENIED:
                //x.innerHTML="User denied the request for Geolocation."
                //  $('#showareainfo').text("User denied the request for Geolocation.");
            break;
            case error.POSITION_UNAVAILABLE:
                // x.innerHTML="Location information is unavailable."
                // $('#showareainfo').text("Location information is unavailable.");
            break;
            case error.TIMEOUT:
                //  x.innerHTML="The request to get user location timed out."
                // $('#showareainfo').text("The request to get user location timed out.");
            break;
            case error.UNKNOWN_ERROR:
                // x.innerHTML="An unknown error occurred."
                //  $('#showareainfo').text("An unknown error occurred.");
            break;
        }
        shopdata();
    }
    function shopdata(){
        var tempurl = siteurl+'?r=index/goods-lists&page=@page@';
        tempurl = tempurl.replace('@random@', 1+Math.round(Math.random()*1000)).replace('@page@',page);
        $.getScript(tempurl);
    }
    function showmoreshop(datas){

        var spdatas = eval(datas);
        if(spdatas.length > 0){
            $("#pullUp").show();

            for(i=0;i<spdatas.length;i++){
                var tempdata = 'red';
                var tempdata2 = '营业中';
                if(spdatas[i].opentype != 2){
                    tempdata = '#ccc';
                    tempdata2 = '已打烊';
                }
                if(spdatas[i].opentype ==3){
                    tempdata = 'green';
                    tempdata2 = '可预订';
                }
                var backdata = '';



                if(spdatas[i].shoptype == 1  ){
                    backdata +=' <a href="'+siteurl+'/index.php?ctrl=wxsite&action=shopshow&typelx=mk&id='+spdatas[i].id+'">';
                }else{
                    backdata += '<a href="'+siteurl+'/index.php?ctrl=wxsite&action=shopshow&typelx=wm&id='+spdatas[i].id+'">';
                }
                backdata +='  	 <li> ';
                backdata +='  		<div class="homscrbusinimg"><img src="'+spdatas[i].shoplogo+'"></div> ';
                backdata +='  		<div class="listbox"> ';
                backdata +='  		<div class="homscrbusinR"> ';
                backdata +='  		 <div class="homscrbusint">'+spdatas[i].shopname+'</div> ';
                backdata +='  		 <div class="homscrbusinsale"> ';
                for(j=1;j<=spdatas[i].point;j++){
                    backdata += '<i class="fa fa-star"></i>';
                }
                for(q=1;q<=5-spdatas[i].point;q++){
                    backdata += '<i class="fa fa-star" style="color:#C7C7C7;"></i>';
                }
                backdata +='  		<span>月售'+spdatas[i].ordercount+'单</span></div> ';
                backdata +='  		 <div class="homscrbusinpric" style="overflow:auto;"><span>起送价￥'+spdatas[i].limitcost+'</span><b>|</b><span>配送费￥'+spdatas[i].pscost+'</span> ';
                if(spdatas[i].attrdet.input != undefined && spdatas[i].attrdet.input != '' ){
                    backdata +='  		<b>|</b><span>'+spdatas[i].attrdet.input+'</span>';
                }
                backdata +='  		</div> ';
                backdata +='  		 <div class="homscrbusinadd" >距'+spdatas[i].juli+' &nbsp;'+spdatas[i].address+'</div> ';
                backdata +='  		</div> ';
                backdata +='  		</div> ';
                backdata +='  	</li> ';
                backdata +='  	</a> ';

                //	t4em+=backdata;
                $('#supplierlist').append(backdata);


            }

            setTimeout(function () {
                is_loading = false;
                myScroll.refresh();
                // 数据加载完成后，调用界面更新方法 Remember to refresh when contents are loaded (ie: on ajax completion)
            }, 1000);

            page = Number(page+1);
            //$(".mBxCr").hide();

        }else{
            setTimeout(function () {
                is_loading = false;

                // 数据加载完成后，调用界面更新方法 Remember to refresh when contents are loaded (ie: on ajax completion)
            }, 1000);
            can_show =  false;
            if(page == 1){
                error($('#supplierlist'),'很遗憾,附近商家正在覆盖中...');
                $("#pullUp").hide();

            }else{
                $('.pullUpLabel').text('更多商家,敬请期待中...');
            }
            myScroll.refresh();


        }
    }

</script>

<script>
	var myScroll, pullDownEl, pullDownOffset,pulldowncate,
	pullUpEl, pullUpOffset,generatedCount = 0;

	function pullDownAction () {

	}

	function pullUpAction () {
		if(is_loading == false){
			is_loading = true;
			setTimeout(function () { 
				shopdata();// 数据加载完成后，调用界面更新方法 Remember to refresh when contents are loaded (ie: on ajax completion)
	        }, 400);	// <-- Simulate network congestion, remove setTimeout from production!
		}
	}

	function loaded() {

		pullDownEl = document.getElementById('pullDown');
		pullDownOffset = pullDownEl.offsetHeight;
		pullUpEl = document.getElementById('pullUp');	
		pullUpOffset = pullUpEl.offsetHeight;

		myScroll = new iScroll('wrapper', {
			scrollbarClass: 'myScrollbar', /* 重要样式 */
			useTransition: false, /* 此属性不知用意，本人从true改为false */
			topOffset: pullDownOffset,
			onRefresh: function () {

				if(is_loading == false){
					if (pullDownEl.className.match('loading')) {
						pullDownEl.className = '';
						pullDownEl.querySelector('.pullDownLabel').innerHTML = '下拉刷新...';
					} else if (pullUpEl.className.match('loading')) {
						pullUpEl.className = '';
						pullUpEl.querySelector('.pullUpLabel').innerHTML = '上拉加载更多...';
					}
				}
			},
			onScrollMove: function () {

				if(is_loading == false){
					if (this.y > 1 && !pullDownEl.className.match('flip')) {

						pullDownEl.className = 'flip';
						pullDownEl.querySelector('.pullDownLabel').innerHTML = '松手开始更新...';
						this.minScrollY = 0;
					} else if (this.y < 1 && pullDownEl.className.match('flip')) {
						pullDownEl.className = '';
						pullDownEl.querySelector('.pullDownLabel').innerHTML = '下拉刷新...';
						this.minScrollY = -pullDownOffset;
					} else if (this.y < (this.maxScrollY + 50) && !pullUpEl.className.match('flip')) {
						pullUpEl.className = 'flip';
						pullUpEl.querySelector('.pullUpLabel').innerHTML = '松手开始更新...';
						this.maxScrollY = this.maxScrollY;
					} else if (this.y > (this.maxScrollY + 1) && pullUpEl.className.match('flip')) {

						pullUpEl.className = '';
						pullUpEl.querySelector('.pullUpLabel').innerHTML = '上拉加载更多...';
						this.maxScrollY = pullUpOffset;
					}
				}
			},
			onScrollEnd: function () {

				if(is_loading == false){
					if (this.y < (this.maxScrollY + 50)){

						pullUpEl.className = 'loading';
						pullUpEl.querySelector('.pullUpLabel').innerHTML = '加载中...';				
						pullUpAction();	
					}
				}


			}
		});

		setTimeout(function () { document.getElementById('wrapper').style.left = '0'; }, 200);
	}

    //初始化绑定iScroll控件
    document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false);
    document.addEventListener('DOMContentLoaded', loaded, false);
</script>
<script>
    // banner
	$(function(){ 

		var bullets = document.getElementById('abdcd').getElementsByTagName('span');
		var slider =  Swipe(document.getElementById('slider'), {
			auto: 3000,
			continuous: true,
			callback: function(pos) { 
				var i = bullets.length;
				while (i--) {
					bullets[i].className = ' ';
				}
				bullets[pos].className = 'on'; 
			}
		});  
	});  
</script>
